package com.wondersgroup.aida.chatmemory;

import dev.langchain4j.data.message.AiMessage;
import dev.langchain4j.data.message.UserMessage;
import dev.langchain4j.memory.ChatMemory;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.model.openai.OpenAiChatModel;

/**
 * @author: 紫麒麟vip
 * @create: 2025/2/15
 * Description:
 */
public class HelloWorld {
    public static void main(String[] args) {
        ChatLanguageModel model = OpenAiChatModel.builder()
                .apiKey("demo")
                .modelName("gpt-4o-mini")
                .build();

        // 进行两轮对话

        ChatMemory chatMemory = MessageWindowChatMemory.builder()
                //以消息的条数进行缓存，最多缓存10条消息记录
                .maxMessages(10)
                .build();
        /*ChatMemory chatMemory = TokenWindowChatMemory.builder()
                //根据token进行缓存
                        .build();*/
        chatMemory.add(UserMessage.from("你好，我是jszhao，你是我最好的兄弟，叫做time"));
        AiMessage answer = model.generate(chatMemory.messages()).content();
        System.out.println(answer.text());
        chatMemory.add(answer);

        chatMemory.add(UserMessage.from("jszhao最好的朋友是谁？"));
        AiMessage answer2 = model.generate(chatMemory.messages()).content();
        System.out.println(answer2.text());
        chatMemory.add(answer2);
    }
}
